/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package titanisu.mathUtil;

import java.util.ArrayList;
import java.util.Date;
import java.util.Random;

/**
 *
 * @author Balaji
 */
public class NumberFetcher {

    
    
    /**
     * To return a word for small item
     *
     * @return a random prime less than 100
     */
    public int getPrime(int from, int to) {
        int prime = 2;
//        System.out.println("returns a random prime number less than 100");
        
        ArrayList al = new ArrayList();
        int y = 0;
        
        for (int i = from; i < to; i++) {
            if (isPrime(i)) {
                al.add(y, i);
            }
        }
        
        prime = (Integer)al.get(new Random().nextInt(al.size()));
        
        return prime;

    }

    
    public boolean isPrime(int p){


for(int i = 2; i<p; i++)
    {
      if(p%i==0)
        return false;
    }
    return true;
  }
    
    
    /**
     * To get randomly generated n numbers with all the numbers value less than
     * max value (0 to max-1 inclusive)
     *
     * @param n number of random values required
     * @param max maximum value of random numbers
     * @return int[] array of random unique integers returned.
     */
    public int[] getNDiffnumbers(int n, int max) {
        int[] diffNo = new int[n];
        Random r = new Random(new Date().getTime());

        for (int k = 0; k < n; k++) {
            diffNo[k] = r.nextInt(max);
        }
        boolean allDiff = false;
        do {
            allDiff = false;
            int i = 0, j = 0;
            for (i = 0; i < n - 1; i++) {
                for (j = i + 1; j < n; j++) {

                    if (diffNo[i] == diffNo[j]) {
                        diffNo[i] = new Random(new Date().getTime()).nextInt(max);
                        allDiff = true;
                    }
                }
            }

        } while (allDiff);

        for (int i = 0; i < diffNo.length; i++) {
            diffNo[i] = diffNo[i] + 1;
        }

        return diffNo;
    }

    public int GCD(int a, int b) {
        if (b == 0) {
            return a;
        }
        return GCD(b, a % b);
    }

public int[] simplifyFraction(int a, int b) {
        int[] sim = new int[2];

        int gcdf = GCD(a, b);

        sim[0] = a / gcdf;
        sim[1] = b / gcdf;

        return sim;


    }
}
